import org.lzy.shop.network.KtorApiService
import org.lzy.shop.response.LoginResponse
import org.lzy.shop.response.PicSmsResponse
import org.lzy.shop.viewmodel.repository.BaseRepository
import org.lzy.shop.viewmodel.repository.LoginRepository

class LoginRepositoryImpl : BaseRepository(), LoginRepository {
    override suspend fun login(phone: String, password: String): LoginResponse? {
        return safeApiCall {
            val response = KtorApiService.login(phone, password)
            handleResponse(response)
        }
    }

    override suspend fun loginSms(phone: String, smsCode: String): LoginResponse? {
        return safeApiCall {
            val response = KtorApiService.loginSms(phone, smsCode)
            handleResponse(response)
        }
    }

    override suspend fun getPicSms(): PicSmsResponse? {
        return safeApiCall {
            val response = KtorApiService.getPicSms()
            handleResponse(response)
        }
    }

    override suspend fun sendSms(phone: String, captchaId: String, code: String): String? {
        return safeApiCall {
            val response = KtorApiService.sendSms(phone, captchaId, code)
            handleResponse(response)
        }
    }

    override suspend fun register(phone: String, smsCode: String, password: String, confirmPassword: String): String? {
        return safeApiCall {
            val response = KtorApiService.register(phone, smsCode, password, confirmPassword)
            handleResponse(response)
        }
    }

    override suspend fun loginQQ(accessToken: String, openId: String): LoginResponse? {
        return safeApiCall {
            val response = KtorApiService.loginQQ(accessToken, openId)
            handleResponse(response)
        }
    }
}